iconEuler Examples

Solving ODE with Laplace

by R. Grothmann

Maxima has the Laplace transform and its inverse. Applying this is one method to solve partial differential equations.

Let us solve the following equation

Solving ODE with Laplace

That is a linear, non-homogenous equation.

For the Laplace method, we write the equation in the following way.

>ode &= 'diff(y(t),t,2)+5*'diff(y(t),t)+4*y(t)=t; 

The initial values can be formulated in terms of conditions for y(t).

>&atvalue(y(t),t=0,0); ...
 &atvalue('diff(y(t),t),t=0,0);

Compute the Laplace transform of the equation, and solve it for the Laplace transformation term.

>&laplace(ode,t,s), sol &= solve(%,'laplace(y(t),t,s))
        2
       s  laplace(y(t), t, s) + 5 s laplace(y(t), t, s)
                                                                    1
                                          + 4 laplace(y(t), t, s) = --
                                                                     2
                                                                    s


                                             1
               [laplace(y(t), t, s) = ----------------]
                                       4      3      2
                                      s  + 5 s  + 4 s

Now we can apply the inverse transform to the right hand side and get the solution.

>function ysol(t) &= ilt(rhs(sol[1]),s,t)
                         - t    - 4 t
                        E      E        t   5
                        ---- - ------ + - - --
                         3       48     4   16

Of course, ode2 can do this equation too.

>ode &= 'diff(y,t,2)+5*'diff(y,t)+4*y=t
                          2
                         d y     dy
                         --- + 5 -- + 4 y = t
                           2     dt
                         dt

However, we get an answer with constants.

>sol &= ode2(ode,y,t)
                          - t        - 4 t   4 t - 5
                 y = %k1 E    + %k2 E      + -------
                                               16

With ic2 (two initial conditions), we can compute the constants.

>&ic2(sol,t=0,y=0,'diff(y,t)=0)
                          - t    - 4 t
                         E      E        4 t - 5
                     y = ---- - ------ + -------
                          3       48       16

We can also solve for the constants by hand.

>&solve([at(rhs(sol),t=0)=0,diffat(rhs(sol),t=0)=0],[%k1,%k2]),  ...
 &sol with %[1]
                               1          1
                       [[%k1 = -, %k2 = - --]]
                               3          48


                          - t    - 4 t
                         E      E        4 t - 5
                     y = ---- - ------ + -------
                          3       48       16

This differential equation can also be solved in the following way. We first solve the homogenuous equation

Solving ODE with Laplace

using y=exp(h*t). This yields a polynomial for h.

>&solve(h^2+5*h+4=0)
                          [h = - 4, h = - 1]

We get the solutions

Solving ODE with Laplace

Then we find a special solution using the ansatz

Solving ODE with Laplace

>yab &= a*t+b
                               a t + b

We can solve this comparing coefficients.

>&diff(yab,t,2)+5*diff(yab,t)+4*yab|ratsimp,  ...
   &solve([coeff(%,t,0)=0,coeff(%,t,1)=1],[a,b])
                          4 a t + 4 b + 5 a


                               1        5
                         [[a = -, b = - --]]
                               4        16

Examples